//
//  WelcomeViewController.swift
//  swift_demo_weibo
//
//  Created by 杨兵 on 15/5/14.
//  Copyright (c) 2015年 bing. All rights reserved.
//

import UIKit
import SDWebImage

class WelcomeViewController: UIViewController {

    // 约束
    @IBOutlet weak var toplayout: NSLayoutConstraint!
    // 头像
    @IBOutlet weak var iconView: UIImageView!
    // 欢迎回来
    @IBOutlet weak var textLbl: UILabel!
    
    // 显示完了,就动画,接着就跳到
    override func viewDidAppear(animated: Bool) {
        super.viewDidAppear(animated)
        toplayout.constant = self.view.frame.height - toplayout.constant
        UIView.animateWithDuration(1.0, delay: 0.0, usingSpringWithDamping: 0.8, initialSpringVelocity: 10, options: nil, animations: { () -> Void in
            // 重新布局约束
            self.view.layoutIfNeeded()
        }) { (Bool) -> Void in
            // 动画结束后切换动画,文字显示
            UIView.animateWithDuration(1, animations: { () -> Void in
                self.textLbl.alpha = 1
            }, completion: { (_) -> Void in
                // 动画结束后跳到主页面
                NSNotificationCenter.defaultCenter().postNotificationName(viewControllerNotifi, object: "Main")
            })
            
        }
        
    }
    
    
    // 加载图片
    override func viewDidLoad() {
        super.viewDidLoad()
        // 文字隐藏
        self.textLbl.alpha = 0
        if userInfoShared?.avatar_large != nil {
            let url = NSURL(string: userInfoShared!.avatar_large!)
            iconView.sd_setImageWithURL(url, placeholderImage: UIImage(named: "avatar_default_big"))
        }
    }

    override func didReceiveMemoryWarning() {
        super.didReceiveMemoryWarning()
        // Dispose of any resources that can be recreated.
    }

    

}
